<template>
	<view class="container">
		<!-- 日期搜索栏 -->
		<view class="search-bar">
			<uni-datetime-picker type="date" v-model="currentDate" @change="loadData" placeholder="选择上报日期" />
			<uni-data-select v-model="auditStatus" :localdata="statusOptions" @change="loadData" placeholder="全部状态" />
		</view>

		<!-- 卡片列表 -->
		<view class="card-list">
			<view v-for="item in reportList" :key="item.report_id" class="report-card" @click="handleViewDetail(item)">
				<view class="card-header">
					<text class="employee-name">{{ item.employeeName }}</text>
					<text class="department">{{ item.department }}</text>
				</view>
				<view class="card-body">
					<text class="amount-label">上报金额</text>
					<text class="amount-value">¥{{ item.reportedAmount }}</text>
				</view>
				<view class="card-footer">
					<text class="report-date">{{ item.reportDate }}</text>
				</view>
			</view>
		</view>

		<!-- 空状态 -->
		<view v-if="reportList.length === 0" class="empty-state">
			<image src="/static/empty.png" class="empty-image" />
			<text class="empty-text">当前日期没有上报记录</text>
		</view>
	</view>
</template>
<script>
	import {
		listReports
	} from "@/api/system/cash/reports"
	export default {
		data() {
			return {
				queryData: {},
				currentDate: this.getCurrentDate(), // 默认当天
				reportList: [],
				auditStatus: 'PENDING',
				statusOptions: [{
						value: 'PENDING',
						text: '待审核'
					},
					{
						value: 'APPROVED',
						text: '已通过'
					},
					{
						value: 'REJECTED',
						text: '已驳回'
					},
					{
						value: 'REVOKE',
						text: '撤回'
					},
				]
			}
		},
		onReady: function() {
			
			this.loadData()
		},
		methods: {
			getCurrentDate() {			
				return this.$dateUtils.getLocalDate();
			},
			// 加载数据（示例方法）
			loadData() {
        const hasPermission = (this.$store.state.user.roles || []).includes('admin');
				this.queryData = {}
				this.queryData.reportDate = this.currentDate;
				this.queryData.auditStatus = this.auditStatus;
				if (!hasPermission) {
					this.queryData.employeeId = this.$store.state.user.id
				}
				listReports(this.queryData).then(response => {
					this.reportList = response.rows
				})
			},

			// 查看详情
			handleViewDetail(item) {
				if (item.auditStatus === 'PENDING' || item.auditStatus === 'REJECTED' || item.auditStatus === 'REVOKE') {
					uni.navigateTo({
						url: `/pages/work/cash/audit?id=${item.reportId}`
					})
				} else {
					uni.navigateTo({
						url: `/pages/work/cash/auditInfo?id=${item.reportId}`
					})
				}
			}
		}
	}
</script>

<style scoped>
	/* 搜索栏样式 */
	.search-bar {
		padding: 20rpx;
		background: #fff;
		border-bottom: 1rpx solid #eee;
	}

	/* 卡片样式优化 */
	.report-card {
		background: #fff;
		border-radius: 16rpx;
		padding: 32rpx;
		margin: 20rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
	}

	.card-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 24rpx;
	}

	.employee-name {
		font-size: 34rpx;
		color: #333;
		font-weight: 500;
	}

	.department {
		font-size: 26rpx;
		color: #666;
		background: #f5f5f5;
		padding: 6rpx 16rpx;
		border-radius: 8rpx;
	}

	.card-body {
		display: flex;
		align-items: baseline;
		gap: 20rpx;
		margin-bottom: 24rpx;
	}

	.amount-label {
		font-size: 28rpx;
		color: #999;
	}

	.amount-value {
		font-size: 42rpx;
		color: #e64340;
		font-weight: bold;
	}

	.card-footer {
		border-top: 1rpx solid #eee;
		padding-top: 20rpx;
	}

	.report-date {
		font-size: 26rpx;
		color: #999;
	}

	.empty-state {
		padding-top: 120rpx;
		text-align: center;
	}

	.empty-image {
		width: 240rpx;
		height: 240rpx;
		opacity: 0.6;
	}

	.empty-text {
		display: block;
		color: #999;
		margin-top: 32rpx;
		font-size: 28rpx;
	}
</style>